package com.example.notifycationtest;

import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationCompatExtras;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    private Button button;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        button = findViewById(R.id.send_notice);
        button.setOnClickListener(new View.OnClickListener() {
            @RequiresApi(api = Build.VERSION_CODES.O)
            @Override
            public void onClick(View v) {
                NotificationManager notificationManager = (NotificationManager)
                        getSystemService(
                                NOTIFICATION_SERVICE);
                Intent intent = new Intent(MainActivity.this,NotificationActivity.class);
                PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this,
                        1,intent,0);
                Notification notification =  new NotificationCompat.Builder(MainActivity.this)
                       .setContentTitle("This is content title ")
                       .setContentText("This is content text")
                        .setWhen(System.currentTimeMillis())
                       .setSmallIcon(R.mipmap.ic_launcher)
                       .setLargeIcon(BitmapFactory.decodeResource(
                                       getResources(),R.mipmap.ic_launcher))
                        .setContentIntent(pendingIntent)
                       // .setAutoCancel(true)
                       .build();

               notificationManager.notify(1,notification);
            }
        });
    }
}
